package learn;

import java.awt.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 标题：
 * 功能：
 *
 * @Author 赵力 <ikcai.com>
 * @Date 2016/12/19 17:02
 * @Class IntelliJ IDEA
 */
public class LearnLambda {
    public static void main(String[] args) {
        List<Apple> apples = new ArrayList<>();
        Apple a1= new Apple(1L,Color.red,12.0f,"山西");
        Apple a2= new Apple(2L,Color.red,8.0f,"山东");
        Apple a3= new Apple(3L,Color.green,12.0f,"陕西");
        apples.add(a1);
        apples.add(a2);
        apples.add(a3);
        filterApplesByAppleFilter(apples,(Apple apple)-> Color.RED.equals(apple.getColor())&&apple.getWeight()>=8).stream().forEach(apple ->
            System.out.println(apple.getOrigin()));
        apples.sort(Comparator.comparing(Apple::getWeight));
        apples.stream().forEach(System.out::println );

    }

    public static List<Apple> filterApplesByAppleFilter(List<Apple> apples, AppleFilter filter)
    {
        List<Apple> filterApples  = new ArrayList<>();
        for(final Apple apple:apples)
        {
            if(filter.acdept(apple))
            {
                filterApples.add(apple);
            }
        }
        return filterApples;
    }
}
